{extend name="$BASE_LIST" /}
{block name="body"}
<div class="right-main">
    <div class="page_nav" id="js_page_nav"><span class="page_title">{$page_nav}</span></div>
    <div id="js_main_header" class="ui-form main_header">
        <span>
            <select id="type" class="form-control" style="width:130px">
                <option value="">选择类型</option>
                <option value="0">短视频</option>
                <option value="1">影片</option>
            </select>
        </span>
        <span>
            <select id="show" class="form-control" style="width:130px">
                <option value="">选择状态</option>
                <option value="0">下线</option>
                <option value="1">上线</option>
            </select>
        </span>
<!--         <span class="frm_input_box search append">
            <a href="javascript:void(0);" id="js_search" class="frm_input_append">
                <i class="icon wb-search" title="搜索"></i>
            </a>
        </span>
 -->        
        <span class="right">
            <button type="button" id="js_addBtn" class="btn btn-primary"><i class="icon wb-plus"></i> 添加分类</button>
        </span>
    </div>
    <table id="grid-table">
        <thead frozen="true">
        <th data-options="field:'video_type',width:140,align:'center',formatter:formatType">类型</th>
        <th data-options="field:'is_show',width:140,align:'center',formatter:formatShow">状态</th>
        <th data-options="field:'class_title',width:140,align:'center'">分类标题</th>
        <th data-options="field:'order_index',width:140,align:'center'">排序（越大越前）</th>
        </thead>
        <thead>
            <tr>
                <th data-options="field:'_oper',halign:'center',formatter: formatOper">操作</th>
            </tr>
        </thead>
    </table>
</div>
{/block}
{block name="script"}
<script type="text/javascript">
    function formatOper(value, row, index) {
        var html = '<span class="grid-operation">';
        html += '<button type="button" onclick="edit(' + row['id'] + ')" class="btn btn-xs btn-default edit-btn"><i class="icon wb-edit"></i>编辑</button>';
        html += '<button type="button" onclick="del(' + row['id'] + ')" class="btn btn-xs btn-default edit-btn"><i class="icon wb-edit"></i>删除</button>';
        html += '</span>';
        return html;
    }
    
    function formatType(value){
        if(value==1){
            return '影片'
        }else{
            return '短视频'
        }
    }

    function formatShow(value){
        if(value==1){
            return '<span style="color:green">上线</span>'
        }else{
            return '<span style="color:red">下线</span>'
        }
    }
    $(function () {
        $('#grid-table').datagrid({
            url: getURL('loadList'),
            method: "GET",
            height: getGridHeight(),
            rownumbers: true,
            singleSelect: true,
            remoteSort: false,
            multiSort: true,
            emptyMsg: '<span>无相关数据</span>',
            pagination: true,
            pageSize: 20
        });
        //设置分页控件 
        $('#grid-table').datagrid('getPager').pagination({
            pageSize: 20, //每页显示的记录条数，默认为10 
            pageList: [20, 30, 50]
        });
    });
    
    $("#js_addBtn").click(function () {
        var url = getURL('edit');
        openBarWin('添加视频', 800, 400, url, function () {
            reload();
        });
    });

    function edit(id) {
        var url = getURL('edit', 'id=' + id);
        openBarWin('编辑', 800, 400, url, function () {
            reload();
        }, ['确定','取消']);
    }

    function del(id) {
        confirm("确认要删除此视频吗？", function () {
            var url = getURL('del');
            $.getJSON(url, {id: id}, function (json) {
                if (json.success)
                    reload();
                else
                    alert(json.message);
            });
        });
    }
    
    $('#type').change(function(){
        reload();
    })

    $('#show').change(function(){
        reload();
    })

    function reload() {
        var show  = $("#show").val();
        var type = $("#type").val();
        $('#grid-table').datagrid('reload', {
            show: show,
            type: type,
        });
    }

</script>
{/block}